package com.audi.handler;

import java.util.ArrayList;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;

import com.audi.dto.DeviceItem;
import com.audi.dto.HistoryItem;
import com.audi.dto.SmartTriggerWhenTriggerItem;

/**
 * @author PhongNT11
 * 
 */
public class HistoryHandler extends Handler {
	/**
	 * 
	 */
	protected HistoryHandler() {
		super();
	}

	/**
	 * processMessage
	 * 
	 * @param actionId
	 *            int
	 * @param data
	 *            String
	 * @return Message
	 * @see message.arg1 = 0 if return successful, message.arg1 = -1 if fail
	 */
	public Message process(int actionId, String data) {
		Message message = new Message();
		Bundle dataBundle = new Bundle();
		message.arg1 = 0;
		String key = String.valueOf(actionId);
		try {
			switch (actionId) {
			case GET_HISTORY_LIST:
				dataBundle.putSerializable(key, json2ListHistory(data));
				break;
			default:
				break;
			}
		} catch (Exception e) {
			Log.e("Client.handler", "[DeviceHandler.java]: " + e.toString());
			message.arg1 = -1;
		}
		message.setData(dataBundle);
		return message;
	}

	public ArrayList<HistoryItem> json2ListHistory(String data) {
		ArrayList<HistoryItem> result = (ArrayList<HistoryItem>) convertJson2List(
				data, HistoryItem.class);
		return result;
	}
}
